/**
 * @Description 维护用户模块
 * @author 焦政
 * @date 2019/4/27
 */

const user = {
    state: {
        longitude: wx.getStorageSync('longitude'),//经度
        latitude: wx.getStorageSync('latitude'),//纬度
        province: wx.getStorageSync('province'),//省份
        city: wx.getStorageSync('city'),//城市
        district: wx.getStorageSync('district'),//区县
        street: wx.getStorageSync('street'),//街道
        streetnumber: wx.getStorageSync('streetnumber'),//街号
        position: wx.getStorageSync('position') || '济南',//街道名称
    },
    mutations: {
        SET_LONGITUDE: (state, longitude) => {
            state.longitude = longitude;
        },
        SET_LATITUDE: (state, latitude) => {
            state.latitude = latitude;
        },
        SET_POSLABEL: (state, position) => {
            state.position = position
        },
        SET_PROVINCE: (state, province) => {
            state.province = province
        },
        SET_CITY: (state, city) => {
            state.city = city
        },
        SET_DISTRICT: (state, district) => {
            state.district = district
        },
        SET_STREET: (state, street) => {
            state.street = street
        },
        SET_STREETNUMBER: (state, streetnumber) => {
            state.streetnumber = streetnumber
        }
    },
    actions: {
        SetRedeemData({commit}, exchange) {
            commit('SET_LONGITUDE', exchange.longitude);
            commit('SET_LATITUDE', exchange.latitude);
            commit('SET_POSLABEL', exchange.position);
            commit('SET_PROVINCE', exchange.province);
            commit('SET_CITY', exchange.city);
            commit('SET_DISTRICT', exchange.district);
            commit('SET_STREET', exchange.street);
            commit('SET_STREETNUMBER', exchange.streetnumber);
        },
        GetRedeemData({state}) {
            console.log(state)
            return new Promise((resolve) => {
                let obj = {
                    longitude: state.longitude,
                    latitude: state.latitude,
                    position: state.position,
                    province: state.province,
                    city: state.city,
                    district: state.district,
                    street: state.street,
                    streetnumber: state.streetnumber,
                };
                resolve(obj);
            });
        },
        // RetreatSafely() {
        //     removeToken();
        //     sessionStorage.clear();
        //     localStorage.clear();
        // }
    }
};

export default user;
